package br.ufrj.dcc.xml.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import br.ufrj.dcc.xml.ActionConstants;

public class QueryForm extends JFrame  implements ActionConstants {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPanel = null;
	private JComboBox jComboBoxTipoBusca = null;
	private JLabel jLabel = null;
	private JLabel jLabel1 = null;
	private JLabel jLabel2 = null;
	private JComboBox jComboBoxDocument = null;
	private JTextArea jTextAreaQuery = null;
	private JLabel jLabel3 = null;
	private JTextArea jTextAreaResult = null;
	private JButton jButtonLimpar = null;
	private JButton jButtonExecutarBusca = null;
	private JScrollPane jScrollPane = null;
	private JScrollPane jScrollPane1 = null;

	/**
	 * This method initializes 
	 * 
	 */
	public QueryForm() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 */
	private void initialize() {
        this.setSize(new Dimension(677, 394));
        this.setTitle("Buscas");
        this.setContentPane(getJContentPanel());
        
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        Dimension screenSize = toolkit.getScreenSize();         
        int x = (screenSize.width - this.getWidth()) / 2;
        int y = (screenSize.height - this.getHeight()) / 2;

        this.setLocation(x, y);         
	}

	/**
	 * This method initializes jContentPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPanel() {
		if (jContentPanel == null) {
			
			
			
			GridBagConstraints gridBagConstraints9 = new GridBagConstraints();
			gridBagConstraints9.fill = GridBagConstraints.BOTH;
			gridBagConstraints9.gridwidth = 3;
			gridBagConstraints9.gridx = 0;
			gridBagConstraints9.gridy = 3;
			gridBagConstraints9.ipadx = 628;
			gridBagConstraints9.ipady = 34;
			gridBagConstraints9.weightx = 1.0;
			gridBagConstraints9.weighty = 0.3;
			gridBagConstraints9.insets = new Insets(3, 17, 3, 17);
			GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.fill = GridBagConstraints.BOTH;
			gridBagConstraints8.gridwidth = 3;
			gridBagConstraints8.gridx = 0;
			gridBagConstraints8.gridy = 5;
			gridBagConstraints8.ipadx = 632;
			gridBagConstraints8.ipady = 72;
			gridBagConstraints8.weightx = 1.0;
			gridBagConstraints8.weighty = 1.0;
			gridBagConstraints8.insets = new Insets(4, 16, 11, 14);
			GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
			gridBagConstraints7.insets = new Insets(12, 43, 7, 17);
			gridBagConstraints7.gridy = 6;
			gridBagConstraints7.ipadx = 44;
			gridBagConstraints7.ipady = 1;
			gridBagConstraints7.anchor = GridBagConstraints.EAST;
			gridBagConstraints7.gridx = 2;
			GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.insets = new Insets(13, 19, 6, 246);
			gridBagConstraints6.gridx = 0;
			gridBagConstraints6.gridy = 6;
			gridBagConstraints6.ipadx = 93;
			gridBagConstraints6.ipady = 1;
			gridBagConstraints6.gridwidth = 2;
			GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.insets = new Insets(4, 17, 3, 264);
			gridBagConstraints5.gridx = 0;
			gridBagConstraints5.gridy = 4;
			gridBagConstraints5.ipadx = 13;
			gridBagConstraints5.ipady = 9;
			gridBagConstraints5.gridwidth = 2;
			GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.fill = GridBagConstraints.BOTH;
			gridBagConstraints4.gridx = 1;
			gridBagConstraints4.gridy = 1;
			gridBagConstraints4.ipadx = 237;
			gridBagConstraints4.weightx = 1.0;
			gridBagConstraints4.anchor = GridBagConstraints.WEST;
			gridBagConstraints4.gridwidth = 2;
			gridBagConstraints4.insets = new Insets(6, 4, 7, 42);
			GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.insets = new Insets(7, 19, 8, 4);
			gridBagConstraints3.gridy = 1;
			gridBagConstraints3.ipadx = 22;
			gridBagConstraints3.ipady = 7;
			gridBagConstraints3.gridx = 0;
			GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.insets = new Insets(7, 18, 2, 286);
			gridBagConstraints2.gridx = 0;
			gridBagConstraints2.gridy = 2;
			gridBagConstraints2.ipadx = 14;
			gridBagConstraints2.ipady = 7;
			gridBagConstraints2.gridwidth = 2;
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.insets = new Insets(23, 20, 5, 3);
			gridBagConstraints1.gridy = 0;
			gridBagConstraints1.ipadx = 7;
			gridBagConstraints1.ipady = 6;
			gridBagConstraints1.gridx = 0;
			GridBagConstraints gridBagConstraints = new GridBagConstraints();
			gridBagConstraints.fill = GridBagConstraints.BOTH;
			gridBagConstraints.gridx = 1;
			gridBagConstraints.gridy = 0;
			gridBagConstraints.ipadx = 237;
			gridBagConstraints.weightx = 1.0;
			gridBagConstraints.anchor = GridBagConstraints.WEST;
			gridBagConstraints.gridwidth = 2;
			gridBagConstraints.insets = new Insets(20, 4, 5, 42);
			jLabel3 = new JLabel();
			jLabel3.setText("Resultado da consulta:");
			jLabel2 = new JLabel();
			jLabel2.setText("Documento:");
			jLabel1 = new JLabel();
			jLabel1.setText("Texto da Consulta:");
			jLabel = new JLabel();
			jLabel.setText("Tipo de busca:");
			jContentPanel = new JPanel();
			jContentPanel.setLayout(new GridBagLayout());
			jContentPanel.add(getJComboBoxTipoBusca(), gridBagConstraints);
			jContentPanel.add(jLabel, gridBagConstraints1);
			jContentPanel.add(jLabel1, gridBagConstraints2);
			jContentPanel.add(jLabel2, gridBagConstraints3);
			jContentPanel.add(getJComboBoxDocument(), gridBagConstraints4);
			jContentPanel.add(jLabel3, gridBagConstraints5);
			jContentPanel.add(getJButtonLimpar(), gridBagConstraints6);
			jContentPanel.add(getJButtonExecutarBusca(), gridBagConstraints7);
			jContentPanel.add(getJScrollPane(), gridBagConstraints8);
			jContentPanel.add(getJScrollPane1(), gridBagConstraints9);
		}
		return jContentPanel;
	}

	/**
	 * This method initializes jComboBoxTipoBusca	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxTipoBusca() {
		if (jComboBoxTipoBusca == null) {
			jComboBoxTipoBusca = new JComboBox();
			jComboBoxTipoBusca.setBackground(Color.white);
			jComboBoxTipoBusca.addItem("XPath - Implementação padrão da Sun  (na memória)");
			jComboBoxTipoBusca.addItem("XPath - Implementação nossa (no banco) tentativa 1");
			jComboBoxTipoBusca.addItem("XPath - Implementação nossa (no banco) tentativa 2");
		}
		return jComboBoxTipoBusca;
	}
	
	public static final int XPATHSUN = 0;
	public static final int XPATHDATABASE = 1;
	public static final int XPATHDATABASE2 = 2;

	public JComboBox getComboBoxTipoBusca() {
		return getJComboBoxTipoBusca();
	}
	
	
	/**
	 * This method initializes jComboBoxDocument	
	 * 	
	 * @return javax.swing.JComboBox	
	 */
	private JComboBox getJComboBoxDocument() {
		if (jComboBoxDocument == null) {
			jComboBoxDocument = new JComboBox();
			jComboBoxDocument.setBackground(Color.white);
		}
		return jComboBoxDocument;
	}
	
	public JComboBox getComboBoxDocument() {
		return getJComboBoxDocument();
	}

	/**
	 * This method initializes jTextAreaQuery	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	public JTextArea getJTextAreaQuery() {
		if (jTextAreaQuery == null) {
			jTextAreaQuery = new JTextArea();
			jTextAreaQuery.setBackground(Color.white);
		}
		return jTextAreaQuery;
	}

	/**
	 * This method initializes jTextAreaResult	
	 * 	
	 * @return javax.swing.JTextArea	
	 */
	public JTextArea getJTextAreaResult() {
		if (jTextAreaResult == null) {
			jTextAreaResult = new JTextArea();
			jTextAreaResult.setBackground(Color.white);
		}
		return jTextAreaResult;
	}

	/**
	 * This method initializes jButtonLimpar	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonLimpar() {
		if (jButtonLimpar == null) {
			jButtonLimpar = new JButton();
			jButtonLimpar.setText("Limpar");
			ActionListener ac = new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					getJTextAreaQuery().setText("");
					getJTextAreaResult().setText("");
				}
			};
			jButtonLimpar.addActionListener(ac);
		}
		return jButtonLimpar;
	}

	/**
	 * This method initializes jButtonExecutarBusca	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonExecutarBusca() {
		if (jButtonExecutarBusca == null) {
			jButtonExecutarBusca = new JButton();
			jButtonExecutarBusca.setText("Executar Busca");
		}
		return jButtonExecutarBusca;
	}

	/**
	 * This method initializes jScrollPane	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setViewportView(getJTextAreaResult());
		}
		return jScrollPane;
	}

	/**
	 * This method initializes jScrollPane1	
	 * 	
	 * @return javax.swing.JScrollPane	
	 */
	private JScrollPane getJScrollPane1() {
		if (jScrollPane1 == null) {
			jScrollPane1 = new JScrollPane();
			jScrollPane1.setViewportView(getJTextAreaQuery());
		}
		return jScrollPane1;
	}
	
	
	public void setListener(ActionListener listener) {
		getJButtonExecutarBusca().addActionListener(listener);
		getJButtonExecutarBusca().setActionCommand(Integer.toString(EXECUTAR_BUSCA));
	}

}  //  @jve:decl-index=0:visual-constraint="32,24"
